﻿@page "/testexception"
@using Project.Constraints.Common.Attributes
@using System.Diagnostics.CodeAnalysis
@using Project.Constraints.Page
@using Project.Constraints.Store.Models
@using Project.Constraints.UI
@using Project.Web.Shared.Routers
@inherits BasicComponent
@inject ILogger<TestException> Logger
@attribute [PageInfo(Title = "Exception测试", Icon = "fa fa-question-circle-o", ForceShowOnNavMenu = true, GroupId = "test")]
异常测评：@(UI.BuildButton(this).Text("触发异常").OnClick(() => ThrowException("ButtonClick")).Render())
生命周期异常：@(UI.BuildButton(this).Text("触发异常").OnClick(() => Navigator.NavigateTo("/testexception?LifeTime=1")).Render())
生命周期异常：@(UI.BuildButton(this).Text("触发异常ForceLoad").OnClick(() => Navigator.NavigateTo("/testexception?LifeTime=1", true)).Render())
@code {
    [CascadingParameter] public TagRoute? Route { get; set; }
    [SupplyParameterFromQuery] public int LifeTime { get; set; }
    void ThrowException(string state)
    {
        Logger.LogInformation("{state} {RouteUrl}", state, Route?.RouteUrl);
        throw new NotImplementedException(state);
    }

    protected override void OnParametersSet()
    {
        base.OnParametersSet();
        if (LifeTime == 1)
            ThrowException("OnParametersSet");
    }


    protected override void OnInitialized()
    {
        base.OnInitialized();
        if (LifeTime == 1)
            ThrowException("OnInitialized");
    }

    protected override void OnAfterRender(bool firstRender)
    {
        base.OnAfterRender(firstRender);
        if (LifeTime == 1)
            ThrowException("OnAfterRender");
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);
        if (firstRender)
        {
            // ThrowException("OnAfterRenderAsync");
        }
    }

}
